from controllers.base_controllers import BaseController
from services.resource_service import ResourceService


class ResourceController(BaseController):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def get(self):
        arg = self.get_argument_dict(must_keys=["id"], check_token=False)
        result = ResourceService().resource(arg.get("id"))
        return {
            "code": 0,
            "msg": "success",
            "data": result
        }


class ResourcesController(BaseController):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def get(self):
        arg = self.get_argument_dict(check_token=False)

        result_list = ResourceService().resources(arg.get("director_id", None))
        return {
            "code": 0,
            "msg": "success",
            "data": result_list
        }


class CreateResourceController(BaseController):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def post(self):
        arg = self.get_argument_dict(must_keys=["user_id"])

        result = ResourceService().create_resource(video=arg.get("video"),
                                                   video_url=arg.get("video_url"),
                                                   cover_pic=arg.get("cover_pic"),
                                                   title=arg.get("title"),
                                                   info=arg.get("info"),
                                                   category=arg.get("category"),
                                                   director_id=arg.get("director_id"),
                                                   resource_type=arg.get("resource_type"))
        return {
            "code": 0,
            "msg": "success",
            "data": result
        }


class UpdateResourceController(BaseController):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def post(self):
        arg = self.get_argument_dict(must_keys=["user_id"])
        result = ResourceService().update_resource(resource_id=arg.get("id"),
                                                   video=arg.get("video"),
                                                   video_url=arg.get("video_url"),
                                                   cover_pic=arg.get("cover_pic"),
                                                   title=arg.get("title"),
                                                   info=arg.get("info"),
                                                   category=arg.get("category"),
                                                   director_id=arg.get("director_id"),
                                                   resource_type=arg.get("resource_type"))

        return {
            "code": 0,
            "msg": "success",
            "data": result
        }


class RemoveResourceController(BaseController):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def post(self):
        arg = self.get_argument_dict(must_keys=["user_id", "id"])
        result = ResourceService().remove_resource(resource_id=arg.get("id"))
        return {
            "code": 0,
            "msg": "success",
            "data": result
        }
